﻿using System;

namespace EventsExample
{
    class PublishingHouse
    {
        //public delegate void NewMagazineArgs(object sender, MagazineEventArgs e);

        //public event NewMagazineArgs NewMagazine;

        public event EventHandler<MagazineEventArgs> NewMagazine;

        protected virtual void OnNewMagazine(MagazineEventArgs e)
        {
            //EventHandler<MagazineEventArgs> del = NewMagazine as EventHandler<MagazineEventArgs>;

            //if (del != null)
            //    del(this, e);

            if (NewMagazine != null)
                NewMagazine(this, e);
        }

        public void PublishMagazine(string magazineName, int magazineVolume, string magazineText, int count)
        {
            for (int i = 0; i < count; i++)
            {
                Console.WriteLine("Printed: {0}, volume: {1}\n{2}", magazineName, magazineVolume, magazineText);
            }
            Console.WriteLine();
            Console.WriteLine("Magazine was published");
            Console.WriteLine();

            MagazineEventArgs e = new MagazineEventArgs(magazineName, magazineVolume);
            OnNewMagazine(e);
        }
    }
}